#include "CCommIOFunc.h"
extern HMODULE GetModule();
HRESULT GetCandidateAbsPath(std::vector<std::wstring>& outCandPath, std::wstring localPath)
{
	WCHAR orgPath[MAX_PATH] = {0};
	WCHAR exeDirPath[MAX_PATH] = {0};
	WCHAR dllDirPath[MAX_PATH] = {0};
	WCHAR upExeDirPath[MAX_PATH] = {0};
	WCHAR upDllDirPath[MAX_PATH] = {0};
	WCHAR upupExeDirPath[MAX_PATH] = {0};
	WCHAR upupDllDirPath[MAX_PATH] = {0};
	outCandPath.clear();
	outCandPath.resize(7);
	{	
		wcscpy_s(orgPath, MAX_PATH, localPath.c_str());
		WCHAR dllPath[MAX_PATH] = {0};
		HMODULE handle = GetModule();
		GetModuleFileName(handle, dllPath, MAX_PATH);

		WCHAR exePath[MAX_PATH];
		GetModuleFileName(NULL, exePath, MAX_PATH);

		WCHAR* pszFile = wcsrchr(dllPath, '\\');
		pszFile++;    // Moves on from \

		WCHAR dllDir[MAX_PATH] = L"";
		wcsncat_s(dllDir, dllPath, pszFile - dllPath);

		pszFile = wcsrchr(exePath, '\\');
		WCHAR exeDir[MAX_PATH] = L"";
		wcsncat_s(exeDir, exePath, pszFile - exePath);
		swprintf_s(dllDirPath, MAX_PATH, L"%s%s", dllDir, orgPath);
		swprintf_s(upDllDirPath, MAX_PATH, L"%s..\\%s", dllDir, orgPath);
		swprintf_s(upupDllDirPath, MAX_PATH, L"%s..\\..\\%s", dllDir, orgPath);

		swprintf_s(exeDirPath, MAX_PATH, L"%s%s", exeDir, orgPath);
		swprintf_s(upExeDirPath, MAX_PATH, L"%s..\\%s", exeDir, orgPath);
		swprintf_s(upupExeDirPath, MAX_PATH, L"%s..\\..\\%s", exeDir, orgPath);
		_wcslwr_s(orgPath, MAX_PATH);
		_wcslwr_s(dllDirPath, MAX_PATH);
		_wcslwr_s(exeDirPath, MAX_PATH);
		_wcslwr_s(upDllDirPath, MAX_PATH);
		_wcslwr_s(upupDllDirPath, MAX_PATH);
		_wcslwr_s(upExeDirPath, MAX_PATH);
		_wcslwr_s(upupExeDirPath, MAX_PATH);
	}

	outCandPath[0] = orgPath;
	outCandPath[1] = dllDirPath;
	outCandPath[2] = upDllDirPath;
	outCandPath[3] = upupDllDirPath;
	outCandPath[4] = exeDirPath;
	outCandPath[5] = upExeDirPath;
	outCandPath[6] = upupExeDirPath;
	return S_OK;
}